#!/usr/bin/env python
# -*- coding:utf-8 -*-

import openpyxl
import domload
import os

ExcelFileName = input("读取：请输入当前目录excel文件名\r\n")
# ExcelFileName2 = 3
while os.path.exists('./' + ExcelFileName) is False:
    print("当前目录不存在该文件，请重新输入")
    ExcelFileName = ''
    while ExcelFileName == '':
        ExcelFileName = input('读取：请重新输入当前目录excel文件名\r\n')


# 打开excel文件,获取工作簿对象
wb = openpyxl.load_workbook(ExcelFileName)
# 从表单中获取单元格的内容
ws = wb.active  # 当前活跃的表单
# print(ws)
# print(ws['A1'])  # 获取A列的第一个对象
# print(ws['A1'].value)
print('{}行 {}列'.format(ws.max_row, ws.max_column))
f_m = chr(96+ws.max_column)

folderName = input('下载存储：请输入当前目录文件夹名称\r\n')
while folderName == '':
    folderName = input('下载存储：请输入当前目录文件夹名称\r\n')


col_range = ws['A:'+f_m]
f_row_range = ws[1]
row_range = ws[2:ws.max_row]
# print(row_range[0][0].value)
result = []
for col in row_range:
    # 打印BC两列单元格中的值内容
    re = {}
    i = 0
    for col2 in col:
        # 打印BC两列单元格中的值内容
        re[f_row_range[i].value] = col2.value
        i += 1
    result = result + [re]


crawler = domload.Crawler(0.05)  # 抓取延迟为 0.05

crawler.start(folderName, result, 2, 1)
print("\r\n下载结束\r\n")
